package com.itheima.controller;

import com.itheima.dto.PageCate;
import com.itheima.dto.YddCateDTO;
import com.itheima.entity.YddCate;
import com.itheima.result.PageData;
import com.itheima.result.R;
import com.itheima.service.YddCateService;
import com.itheima.vo.YddCateVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: kafka
 * @package: com.itheima.controller
 * @className: YddCateController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/23 17:33
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/ydd_cate")
@AllArgsConstructor
public class YddCateController {
    private final YddCateService yddCateService;

    @GetMapping("/list")
    public R<PageData> page(PageCate pageCate){
        PageData pageData = yddCateService.page(pageCate);
        return R.success(pageData);
    }

    @GetMapping("/all")
    public R<List<YddCateVO>> queryAllCate(){
        List<YddCateVO> yddCateVOList = yddCateService.queryAllCate();
        return R.success(yddCateVOList);
    }

    @PostMapping("/add")
    public R<?> creatYddCate(@RequestBody YddCateDTO yddCateDTO){
        yddCateService.creatYddCate(yddCateDTO);
        return R.success();
    }

    @GetMapping("/del")
    public R<?> deleteYddCate(String id){
        yddCateService.deleteYddCate(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R<YddCateVO> queryYddCate(String id){
        YddCateVO yddCateVO = yddCateService.queryYddCate(id);
        return R.success(yddCateVO);
    }

    @PostMapping("/update")
    public R<?> updateYddCate(@RequestBody YddCateDTO yddCateDTO){
        yddCateService.updateYddCate(yddCateDTO);
        return R.success();
    }
}
